lunovns.fuel = "default:obsidian_shard"
lunovns.fuel_time = 10

function getItemImage(objFuel)
	local props = minetest.registered_items[objFuel]
	if props.inventory_image == nil then 
		props.inventory_image = "" 
	end
	return props.inventory_image
end

function getItemName(objFuel)
	local props = minetest.registered_items[objFuel]
	--[[if props.inventory_image == nil then 
		props.inventory_image = "" 
	end]]--
	return props.description
end


--print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"..getItemName(lunovns.fuel))

lunovns.furnace_inactive_formspec =
	"size[8,6.5]"..
	"list[current_name;fuel;6.0,0.5;1,1;]"..
	"image[0,0;0.8,0.8;"..getItemImage(lunovns.fuel).."]"..
	"label[0.7,0.1; <= Combustivel ("..getItemName(lunovns.fuel)..") ]".. --"..lunovns.fuel.."
	--"label[1.3,0.4; Carga: 0 Volts]"..
	"label[0,1.4; 1º - Estacione o UFO proximo deste tanque!]"..
	--"label[0,1.7; 2º - Pressione botao de correr dentro do UFO!]"..
	"list[current_player;main;0,2.5;8,4;]"


minetest.register_node("lunovns:furnace", {
	description = "Abastecedor (p/ Disco-Voador)",
	tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png",
		"default_steel_block.png", "default_steel_block.png", "default_steel_block.png^ufos_furnace_front.png"},
	paramtype2 = "facedir",
	groups = {cracky=2},
	legacy_facedir_simple = true,
	sounds = default.node_sound_stone_defaults(),
	on_construct = function(pos)
		local meta = minetest.env:get_meta(pos)
		meta:set_string("formspec", lunovns.furnace_inactive_formspec)
		meta:set_string("infotext", "UFO charging device")
		local inv = meta:get_inventory()
		inv:set_size("fuel", 1)
	end,
	can_dig = function(pos,player)
		local meta = minetest.env:get_meta(pos);
		local inv = meta:get_inventory()
		if not inv:is_empty("fuel") then
			return false
		end
		return true
	end,
})

minetest.register_node("lunovns:furnace_active", {
	description = "Abastecedor Ativo",
	tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png",
		"default_steel_block.png", "default_steel_block.png", "default_steel_block.png^ufos_furnace_front.png^ufos_furnace_front_active.png"},
	paramtype2 = "facedir",
	light_source = 8,
	drop = "lunovns:furnace",
	groups = {cracky=2, not_in_creative_inventory=1},
	legacy_facedir_simple = true,
	sounds = default.node_sound_stone_defaults(),
	on_construct = function(pos)
		local meta = minetest.env:get_meta(pos)
		meta:set_string("formspec", lunovns.furnace_inactive_formspec)
		meta:set_string("infotext", "UFO charging device")
		local inv = meta:get_inventory()
		inv:set_size("fuel", 1)
	end,
	can_dig = function(pos,player)
		local meta = minetest.env:get_meta(pos);
		local inv = meta:get_inventory()
		if not inv:is_empty("fuel") then
			return false
		end
		return true
	end,
})

function hacky_swap_node(pos,name)
	local node = minetest.env:get_node(pos)
	local meta = minetest.env:get_meta(pos)
	local meta0 = meta:to_table()
	if node.name == name then
		return
	end
	node.name = name
	local meta0 = meta:to_table()
	minetest.env:set_node(pos,node)
	meta = minetest.env:get_meta(pos)
	meta:from_table(meta0)
end

minetest.register_abm({
	nodenames = {"lunovns:furnace","lunovns:furnace_active"},
	interval = .25,
	chance = 1,
	action = function(pos, node, active_object_count, active_object_count_wider)
		local meta = minetest.env:get_meta(pos)
		local inv = meta:get_inventory()
		local stack = inv:get_stack("fuel",1)
		if stack:get_name() == lunovns.fuel then
			inv:remove_item("fuel",ItemStack(lunovns.fuel))
			meta:set_int("charge",meta:get_int("charge")+1)
			meta:set_string("formspec", lunovns.furnace_inactive_formspec
				--.. "label[0,0;Charge: "..meta:get_int("charge")
				.. "label[1.3,0.4; Carga: ".. meta:get_int("charge") .." Volts]"
			)
		end
	end,
})

minetest.register_craft( {
	output = 'lunovns:furnace',
	recipe = {
		{ "default:steel_ingot", "default:obsidian", "default:steel_ingot"},
		{ "default:obsidian", "default:furnace", "default:obsidian"},
		{ "default:steel_ingot", "default:obsidian", "default:steel_ingot"},
	},
})
minetest.register_alias("abastecedor"		, "lunovns:furnace")
minetest.register_alias("abastecedorufo"	, "lunovns:furnace")
minetest.register_alias("abastecedovn"		, "lunovns:furnace")
minetest.register_alias("abastecedoovn"	, "lunovns:furnace")
minetest.register_alias("fornufo"			, "lunovns:furnace")
minetest.register_alias("fornovn"			, "lunovns:furnace")
minetest.register_alias("fornoovn"			, "lunovns:furnace")


